package beans;
 
import java.io.IOException;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Amauri
 */
@ManagedBean
public class AreaInicialBean {
 
    private final HttpServletRequest httpServletRequest;
    private final FacesContext facesContext;
    private boolean isAdmin; 
    
    public AreaInicialBean(){
        facesContext = FacesContext.getCurrentInstance();
        httpServletRequest = (HttpServletRequest)facesContext.getExternalContext().getRequest();
        
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);  
        
        this.setIsAdmin((boolean)session.getAttribute("isAdmin"));
    }
    
    public void desconectar() throws IOException{
        httpServletRequest.getSession().invalidate();
        facesContext.getExternalContext().redirect("../index.jsf");
    }

    /**
     * @return the isAdmin
     */
    public boolean isIsAdmin() {
        return isAdmin;
    }

    /**
     * @param isAdmin the isAdmin to set
     */
    public void setIsAdmin(boolean isAdmin) {
        this.isAdmin = isAdmin;
    }
    
}
